<template>
         <a-comment >
          <template #avatar>
            <a-avatar :src="user.avatar" :alt="user.userName" />
          </template>
          <template #content>
            <a-form-item>
              <a-textarea :rows="12" v-model:value="addCommentParam.f_c_text" />
            </a-form-item>
            <a-form-item>
              <a-button
                html-type="submit"
                :loading="submitting"
                type="primary"
                @click="addComment"
              >
                提交
              </a-button>
            </a-form-item>
          </template>
        </a-comment>
</template>
<script>
import { message } from "ant-design-vue";
import { get, post, tip } from "@/common"; //基础
import moment from "moment";
import { defineComponent, ref,reactive } from "vue";
export default defineComponent({
  setup() {
    // 当前用户信息
    const user = ref({
      userId: "",
      userName: "",
      avater: "",
    });
    const getCurrnetUser = () => {
      get("/security/home/currentUser").then((res) => {
        console.log(res);
        user.value = res.data;
      });
    };
    getCurrnetUser();

    // 查看评论
    const Comments = ref([]);
    // parentNode
    const getComment = () => {
      post("/forum/freeChat/getHostChat", { p_id: 1 }).then((res) => {
        console.log(res);
        Comments.value = res.data;
        console.log(Comments.value);
      });
    };
    getComment();

    //增加评论
    const submitting = ref(false);
    const addCommentParam = reactive({
      u_id: "",
      p_id: 1,
      f_c_text: "",
    });
    const addComment = () => {
      if (!addCommentParam.f_c_text) {
        message.error("评论不能为空！");
        return;
      }
      addCommentParam.u_id=user.value.userId;
      submitting.value = true;
      post("/forum/freeChat/addHostChat", addCommentParam).then((res) => {
        message.success(res.message);
        submitting.value = false;
        addCommentParam.f_c_text = "";
      });
    };

    return {
      addComment,
      submitting,
      addCommentParam,
      user,
      getCurrnetUser,
      Comments,
      getComment,
      moment,
    };
  },
});
</script>